/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pkl51.component;

import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JLabel;
import javax.swing.Timer;

/**
 *
 * @author Ryan
 */


public class TimeLabel extends JLabel implements ActionListener {

    private String pattern = "dd MMMM yyyy, HH:mm:ss";
    private SimpleDateFormat format;
    private Timer timer;
    private Date date;
    public TimeLabel() {
        setForeground(Color.black);
	timer = new Timer(1000, this);
	format = new SimpleDateFormat(pattern);
	date = new Date();
        timer.start();
    }

    public String getPattern() {
	return pattern;
    }

    public void setPattern(String pattern) {
        this.pattern = pattern;
        format = new SimpleDateFormat(pattern);
    }

    public void start() {
        timer.start();
    }

    public void stop() {
        timer.stop();
    }


    public void actionPerformed(ActionEvent e) {
        date.setTime(System.currentTimeMillis());
        setText(format.format(date));

    }


}
